/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.common.utils;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * Created by Qiang.Chen on 2016/10/25.
 */
public class ImageUtils {

    /**
     * Convert image to gif.
     *
     * @param path file path.
     */
    public static void convertImageToGif(String path) {
        BufferedImage bufferedImage;
        try {

            bufferedImage = ImageIO.read(new File(path));

            BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(),
                    bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
            newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);
            ImageIO.write(newBufferedImage, "gif", new File(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
